package com.simple.datax.bo.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.simple.datax.bo.IDataxDictionaryBO;
import com.simple.datax.dao.IDataxDictionaryDAO;
import com.simple.datax.vo.DataxDictionaryIdVO;
import com.simple.datax.vo.DataxDictionaryVO;
import com.simple.util.object.PageInfoBean;

@Service("dataxDictionaryBO")
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
public class DataxDictionaryBOImpl implements IDataxDictionaryBO {

	@Autowired
	private IDataxDictionaryDAO dataxDictionaryDAO;
	
	@Override
	public DataxDictionaryVO findById(final DataxDictionaryIdVO id) {
		return dataxDictionaryDAO.findById(id);
	}

	@Override
	public List<DataxDictionaryVO> findAll() {
		return dataxDictionaryDAO.findAll();
	}
	
	@Override
	public List<DataxDictionaryVO> findDataxDictionaryVOByPage(PageInfoBean pageInfoBean, String fcCode, String fcName, String fiCatagory) {
		return dataxDictionaryDAO.findDataxDictionaryVOByPage(pageInfoBean, fcCode, fcName, fiCatagory);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void add(DataxDictionaryVO dataxDictionaryVO) {
		dataxDictionaryDAO.saveOrUpdate(dataxDictionaryVO); 
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void edit(DataxDictionaryVO dataxDictionaryVO) {
		final DataxDictionaryVO ddv = dataxDictionaryDAO.findById(dataxDictionaryVO.getId());
		ddv.setFcName(dataxDictionaryVO.getFcName());
		ddv.setFcMemo(dataxDictionaryVO.getFcMemo());
		dataxDictionaryDAO.saveOrUpdate(ddv); 
	}
	
	
	@Override
	public Map<String,String> findMapByCatagory(final String fiCatagory) {
		 List<DataxDictionaryVO> dataxDictionaryVOList = dataxDictionaryDAO.findDataxDictionaryVOByCatagory(fiCatagory);
		 final Map<String ,String> map = new LinkedHashMap<String ,String>();
		 for(final DataxDictionaryVO dataxDictionaryVO: dataxDictionaryVOList){
			 map.put(dataxDictionaryVO.getId().getFcCode(), dataxDictionaryVO.getFcName());
		 }
		 return map;
	}

	@Override
	public List<DataxDictionaryVO> findDataxDictionaryVOByCatagory(
			final String fiCatagory) {
		return dataxDictionaryDAO.findDataxDictionaryVOByCatagory(fiCatagory);
	}

	@Override
	public List<DataxDictionaryVO> findDataxDictionaryVOByEnpterpise(
			String eCode) {
		return dataxDictionaryDAO.findDataxDictionaryVOByEnterprise(eCode);
	}

	@Override
	public List<DataxDictionaryVO> findTransServiceTypeDataxDictionaryVO() {
		return dataxDictionaryDAO.findTransServiceTypeDataxDictionaryVO();
	}


}
